public class test2 {
    //力扣  1004  最大连续1的个数
    public static void main(String[] args) {
        int[] nums = {1,1,1,0,0,0,1,1,1,1,0};
        int k = 2;
        int n = nums.length;
        int left = 0;
        int right = 0;
        int count = 0;
        int zero = 0;
        while (right < n) {
            if(nums[right]==1){
//                right++;
            }else{
                zero++;
            }
            while(zero>k){
                count = Math.max(count,right-left);
                if(nums[left]==0){
                    zero--;
                    left++;
//                    right++;
                }else{
                    left++;
                }
            }
            right++;
        }
        count = Math.max(count,right-left);
        System.out.println(count);

    }
}
